#include "../config.h"

#if USE_I2C
#include "i2c/lm75.h"
#include "usart.h"
#include "sensors.h"

#define CHECK_TW_ERROR(ecode)  status = TW_STATUS; if (status != ecode) return (status >> 3)
#define TW_BUSY_WAIT() while( !(TWCR & (1<<TWINT)))



int8_t read_temp_fleury(int8_t adress)
{ 
	int8_t tmp1;
    tmp1 = i2c_start((adress << 1 ) | TW_WRITE);       // set device address and write mode
	if ( tmp1 ) {
        /* failed to issue start condition, possibly no device found */
		i2c_stop();
		return -127;
    }else {
        /* write ok, read value , wait until the device is no longer busy from the previous write operation */
		i2c_rep_start((adress << 1 ) | TW_READ);       // set device address and read mode
        tmp1 = i2c_readNak();                    // read one byte
		i2c_stop();
	}        
  return tmp1;
}
#endif //USE_I2C